package core


type Function interface {
	Call(args ([] Object), ctx ([] Object), h RuntimeHandle) Object
}

type NativeFunction func(args ([] Object), ctx ([] Object), h RuntimeHandle) Object
func (f NativeFunction) Call(args ([] Object), ctx ([] Object), h RuntimeHandle) Object {
	return f(args, ctx, h)
}

func FunctionToLambda(op Function, destruct bool, ctx ([] Object), h RuntimeHandle) Lambda {
	if destruct {
		return Lambda {
			Call: func(arg Object) Object {
				var args = (*arg).(Record).Objects
				return op.Call(args, ctx, h)
			},
		}
	} else {
		return Lambda {
			Call: func(arg Object) Object {
				var args = [] Object { arg }
				return op.Call(args, ctx, h)
			},
		}
	}
}
func FunctionToLambdaObject(op Function, destruct bool, ctx ([] Object), h RuntimeHandle) Object {
	var o = ObjectImpl(FunctionToLambda(op, destruct, ctx, h))
	return &o
}


